package com.soft.dao;

import com.soft.entity.OrderReturnRecord;
import com.soft.util.Connect;

import java.util.ArrayList;
import java.util.List;

public class OrderReturnRecordDao {

    Class<OrderReturnRecord> orderReturnRecordClass;

    public OrderReturnRecordDao() {
        orderReturnRecordClass = OrderReturnRecord.class;
    }

    /**
     * @Author: 孔子雄
     * @Description: 通过orderId获取退货处理记录
     * @DateTime: 2021/5/25 11:03
     * @Params: orderId：订单Id
     * @Return: OrderReturnRecord
     */
    public OrderReturnRecord getByOrderId(int orderId) {
        List<Object> param = new ArrayList<Object>();
        param.add(orderId);

        String sql = "select * from orderReturnRecord where orderId = ?";
        return Connect.getInstance().queryObject(sql, param, orderReturnRecordClass);
    }

    /**
     * @Author: 孔子雄
     * @Description: 根据Id获得退货处理记录
     * @DateTime: 2021/5/25 20:58
     * @Params: id ：记录编号
     * @Return: OrderReturnRecord
     */
    public OrderReturnRecord get(int id) {
        List<Object> param = new ArrayList<Object>();
        param.add(id);

        String sql = "select * from orderReturnRecord where id = ?";
        return Connect.getInstance().queryObject(sql, param, orderReturnRecordClass);
    }

    /**
     * @Author: 孔子雄
     * @Description: 保存退货处理记录
     * @DateTime: 2021/5/25 21:08
     * @Params: ord 退货处理记录实体
     * @Return: boolean
     */
    public boolean update(OrderReturnRecord ord) {
        List<Object> param = new ArrayList<Object>();
        param.add(ord.getOrderId());
        param.add(ord.getResult());
        param.add(ord.getAddress());
        param.add(ord.getReason());
        param.add(ord.getId());

        String sql = "update orderReturnRecord set orderId=?, result=?, address=?, reason=? where id=?";

        int flag = Connect.getInstance().execute(sql, param);
        if (flag != 0) {
            return true;
        }
        return  false;
    }

    public boolean insert(OrderReturnRecord ord) {
        List<Object> param = new ArrayList<Object>();
        param.add(ord.getOrderId());
        //param.add(ord.getResult());
        param.add(ord.getAddress());
        param.add(ord.getReason());

        String sql = "insert into orderReturnRecord(orderId, address, reason) value (?,?,?)";

        int flag = Connect.getInstance().execute(sql, param);
        if (flag != 0) {
            return true;
        }
        return  false;
    }

}
